package com.sgy.netty.init;

import com.sgy.netty.handler.MyMatchingHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;

public class MyChannelInitializer extends ChannelInitializer {
    @Override
    protected void initChannel(Channel channel) throws Exception {
        ChannelPipeline pipeline = channel.pipeline();
        //http消息编码解码
        pipeline.addLast("http-codec",new HttpServerCodec());
        //http消息组装
        pipeline.addLast("aggregator",new HttpObjectAggregator(65536));
        //WebSocket通信支持
        pipeline.addLast("http-chunked",new ChunkedWriteHandler());
        //自定义处理类
        pipeline.addLast("handler",new MyMatchingHandler());
    }
}
